<?php
// AccountListLogic::run() cho doan code nay vao duoi cung
		$dbn = 'proxydb';

		$dao= new AccountDao($db);
		$list = $dao->selectStatement("use " . $dbn);
		$list = $dao->selectStatement("show tables");

		$conn = mysql_connect('localhost', 'root', '');
		mysql_query('create database '. $dbn);
		mysql_select_db($dbn, $conn);
		//var_dump($list);

		$cnt = count($list);
		for ($i = 0; $i < $cnt; $i++) {
			$table  = $list[$i]['Tables_in_'.$dbn];
			$ret = $dao->selectStatement("show create table " . $table);
			$create = $ret[0]['Create Table'];
			mysql_query($create);
		}

		$list = $dao->selectStatement("use " . 'adpv6_2');
// tao dinh nghia cac bang
// cvListLogic::run
// tao desc
		// desc[id] = array(type=>number);
		// desc[name] = array(type=>text);
		// ...
		$table = "summary_track";

		$arr = explode("_", $table);
		$c = count($arr);
		$cl = "";
		for ($i = 0; $i < $c; $i++) {
			$cl .= ucfirst($arr[$i]);
		}

		$daoClass = $cl."Dao";
		require_once 'common/dao/account/summary/'.$daoClass.'.php';

		$dao= new $daoClass($accountDb);
		$ret = $dao->selectStatement("desc " . $table);
		$desc = array();
		$cnt = count($ret);
		for ($i = 0; $i < $cnt; $i++) {
			$type = strpos($ret[$i]['Type'], 'int') !== false ? 'number' : 'text';
			$desc[$ret[$i]['Field']] =  array('type'=>$type);
		}
		//var_dump($desc);
		//end tao desc

		$dao = new $daoClass($accountDb);
		$dao->setLimit(0,3000);
		$list = $dao->select();
		$conn = mysql_connect('localhost', 'root', '');
		mysql_select_db('adpv6_2', $conn);
		try {
			foreach ($list as $r) {
				$dao = new $daoClass($accountDb);
				foreach ($desc as $k => $inf) {
					if($inf['type'] == 'number') $dao->addColVal($k, $r[$k]);
					else $dao->addColValStr($k, $r[$k]);
				}
				try {
					$dao->insert($form, false, false, true);
				} catch (Exception $e) {
				}
			    //$d = new AccountDao($db);
				//$d->insert($form, false, false, true);
				//$d->setLimit($limit)
			}
		} catch (Exception $e) {
		}
// cvListLogic::run

// AppDao
	public function insert($form, $addsInsertDatetime=true, $isLog=false, $m = false ) {
		if($addsInsertDatetime) $this->addValue(self::_COL_INSERT_DATETIME, 'Now()');
		parent::insert($m);

//		if (!$isLog)	$this->writeUpdateLog(1, $form);
//		echo ('<br>');
//		echo (parent::getLastInsertId());
	}

// Dao
	public function insert($m=false) {
		// INSERT INTO table
		$sql = "INSERT INTO " . $this->table;

		// SET col1=val1, col2=val2
		$sql .= $this->getSetSql();

		if($m) mysql_query($sql);
		else
		$this->db->executeUpdate($sql);
	}


	// insert proxydb
	// tao desc
		// desc[id] = array(type=>number);
		// desc[name] = array(type=>text);
		// ...
		$dbn = 'proxydb';
		$table = "test_month_201103";
		$dao= new AccountDao($db);
		$dao->selectStatement("use " . $dbn);

		$arr = explode("_", $table);
		$c = count($arr);
		$cl = "";
		for ($i = 0; $i < $c; $i++) {
			$cl .= ucfirst($arr[$i]);
		}

		$dao= new AccountDao($db);

		$ret = $dao->selectStatement("desc " . $table);
		$desc = array();
		$cnt = count($ret);
		for ($i = 0; $i < $cnt; $i++) {
			$type = strpos($ret[$i]['Type'], 'int') !== false ? 'number' : 'text';
			$desc[$ret[$i]['Field']] =  array('type'=>$type);
		}
		//var_dump($desc);
		//end tao desc

		$dao = new AccountDao($db, $table);
		$dao->setLimit(0,3000);
		$list = $dao->select();
		$conn = mysql_connect('localhost', 'root', '');
		mysql_select_db('proxydb', $conn);
		try {
			foreach ($list as $r) {
				$dao = new AccountDao($db, $table);
				foreach ($desc as $k => $inf) {
					if($inf['type'] == 'number') $dao->addColVal($k, $r[$k]);
					else $dao->addColValStr($k, $r[$k]);
				}
				try {
					$dao->insert($form, false, false, true);
				} catch (Exception $e) {
				}
			    //$d = new AccountDao($db);
				//$d->insert($form, false, false, true);
				//$d->setLimit($limit)
			}
		} catch (Exception $e) {
		}

		$dao->selectStatement("use " . 'adpv6_0');
// end insert proxy
